package com.stein;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;


public class Assets {

	
	//------ cool menu ------------
		
	private final static String FILE_IMAGE_ATLAS = "data/imageatlas/pages.atlas";
	private final static String FILE_UI_SKIN = "skin/uiskin.json";
	public static TextureAtlas imageAtlas;
	public static Skin skin;
	
	public static TextureRegion backgroundRegion;
//	
	public static Texture items;

	 


	public static BitmapFont font;
	
	

	
	//===================================================
	

	public static BitmapFont font10_en;
	public static BitmapFont font12_en;
	public static BitmapFont font15_en;
	public static BitmapFont font17_en;
	public static BitmapFont font20_en;
	
	public static BitmapFont font10_de;
	
	public static BitmapFont font10_pl;
	
	public static BitmapFont font10_es;

	
	
	
	public static Texture loadTexture (String file) {
		return new Texture(Gdx.files.internal(file));
	}
	
	
    public static Skin getSkin(){
        if( skin == null ) {
            FileHandle skinFile = Gdx.files.internal(FILE_UI_SKIN);
            skin = new Skin( skinFile );
        }
        return skin;
    }
	
 
		
	private static void releaseResources() {
		skin = null;
		
		// TODO: unload assetmgr. ?
	}
	
	
	public static void loadRessources (AssetManager m_assetManager) {
		
		//----- BACKGROUND -------------------------------
		TextureParameter param;
		param = new TextureParameter();
		param.minFilter = TextureFilter.Linear;
//		param.genMipMaps = true;
		m_assetManager.load("data/background.png", Texture.class, param);
		
	    
		//----- ITEMS (ImageAtlas) -------------------------------
		m_assetManager.load(FILE_IMAGE_ATLAS, TextureAtlas.class);		
		
		
		//------- FONTS ------------------------------------
//		m_assetManager.load("data/font2.fnt", BitmapFont.class);
		m_assetManager.load("data/font.fnt", BitmapFont.class);
		
		
	}	
	
	
	
	
	public static void assignRessources (AssetManager m_assetManager) {
				
		
		//---------------------- BACKGROUND -------------------------------
		if (m_assetManager.isLoaded("data/background.png")) {
			
			backgroundRegion = new TextureRegion(m_assetManager.get("data/background.png", Texture.class), 0, 0, 800, 480);	
		}
		
		//--------------- ITEMS ----------------------------------------------------
		if (m_assetManager.isLoaded(FILE_IMAGE_ATLAS)) {
					

			

			
			//---------- FONTS ----------------------------------------------			
			font = m_assetManager.get("data/font.fnt", BitmapFont.class);
			font.setUseIntegerPositions(false);			//----------------------------------------------------------------- bringt das �berhaupt was?
			font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);	//--------------------- bringt das �berhaupt was?
			
			//---- generate freetype font dynamically -----------------
			
			loadFont();
		}
	}

 
	public static void loadFont () {

		FreeTypeFontGenerator generator;
		
		int screenWidth = Gdx.graphics.getWidth();
		int screenHeight = Gdx.graphics.getHeight();
		int fontSize = 20;
		
		if (screenWidth >= 600)		fontSize = 26;
		if (screenWidth >= 800) 	fontSize = 26;
		if (screenWidth >= 1280) 	fontSize = 26;
			
		
		generator = new FreeTypeFontGenerator(Gdx.files.internal("data/ARIAL.TTF"));
		font10_en = generator.generateFont(fontSize);

//		generator = new FreeTypeFontGenerator(Gdx.files.internal("data/ltromatic.ttf"));
//		font12_en = generator.generateFont(Math.round(fontSize / 1.2f));
//		
//		generator = new FreeTypeFontGenerator(Gdx.files.internal("data/ltromatic.ttf"));
//		font15_en = generator.generateFont(Math.round(fontSize / 1.5f));
//		
//		generator = new FreeTypeFontGenerator(Gdx.files.internal("data/ltromatic.ttf"));
//		font17_en = generator.generateFont(Math.round(fontSize / 1.7f));
//		
//		generator = new FreeTypeFontGenerator(Gdx.files.internal("data/ltromatic.ttf"));
//		font20_en = generator.generateFont(Math.round(fontSize / 2f));

		
		
		generator = new FreeTypeFontGenerator(Gdx.files.internal("data/ARIAL.TTF"));
		font10_de = generator.generateFont(fontSize);

		generator = new FreeTypeFontGenerator(Gdx.files.internal("data/ARIAL.TTF"));
		font10_pl = generator.generateFont(fontSize);
		
		generator = new FreeTypeFontGenerator(Gdx.files.internal("data/ARIAL.TTF"));
		font10_es = generator.generateFont(fontSize);
		
		
		//---------------------------------------------------------------------------------
		
		
//			generator = new FreeTypeFontGenerator(Gdx.files.internal("data/ARIAL.TTF"));
//			font24_de = generator.generateFont(fontSize);
//			
//			generator = new FreeTypeFontGenerator (Gdx.files.internal("data/ARIAL.TTF"));
//			font24_pl = generator.generateFont(fontSize , "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdęfghijklmnopqrstuvwxyź1234567890\"!`?'.,;:()[]{}<>|/@\\^$-%+=#_&~*" , false );
//	//		font24_pl = generator.generateFont(fontSize);
		
		generator.dispose();


	}
	
	
}






